package com.pandora.loan.home.enums;

/**
 * @author developer
 */
public enum ExceptionEnum {

    // BadRequest: request (400001 - 400099)
    EmptyRequestError(400001, "请求不可为空!"),
    InvalidRequestError(400002, "请求不合法(400002)!"),
    RequestParameterError(400003, "请求参数错误!"),

    // BadRequest: access_token(4001**)
    EmptyAppIDError(400101, "请求不合法(400101)!"),
    InvalidAppIDError(400102, "请求不合法(400102)!"),
    EmptyAppSecretError(400103, "请求不合法(400103)!"),
    InvalidAppSecretError(400104, "请求不合法(400104)!"),
    EmptyTimestampError(400105, "请求不合法(400105)!"),
    InvalidTimestampError(400106, "请求不合法(400106)!"),

    // BadRequest : no invalid (400201 - 400299)
    MobileNoInvalidError(400201, "手机号不合法!"),
    EmptySignError(400107, "请求不合法(400107)!"),
    InvalidSignError(400108, "请求不合法(400108)!"),
    EmptyTerminalIDError(400109, "请求不合法(400109)!"),
    MobilePasswordRequiredError(400110, "手机号密码必填!"),
    CertificationInvalidError(400111, "实名认证失败，请仔细核对信息!"),
    Card4EmptyError(400112, "四要素信息不可为空!"),

    // Unauthorized: (401001 - 401099)
    AccessTokenRequiredError(401001, "请求不合法(401001)!"),
    AccessTokenExpiredError(401002, "请求不合法(401002)!"),
    AccessTokenInvalidError(401003, "请求不合法(401003)!"),
    AuthorizationTokenInvalidError(401004, "请求不合法(401004)!"),

    // NotFound: access_token (404001 - 404099)
    AppIDNotFoundError(404001, "请求不合法(404001)!"),
    CustomerNotFoundError(404002, "用户不存在!"),
    SMSCodeNotFoundError(404003, "短信不存在!"),
    SMSCodeWrongError(404003, "短信验证码错误"),
    DBNotFoundError(404004, "数据库资源未找到!"),
    ReportNotExistedError(404005, "报告不存在!"),
    InvalidDataError(404007, "获取数据错误!"),
    CertificationFrequentlyError(404008, "实名认证次数达到上限!"),
    CustomerAlreadyExists(403001, "此用户已存在！"),
    CustomerNotExists(403002, "此用户不存在"),

    // InternalServerError: (500001 - 500099)
    EmptyPubKeyError(500001, "服务异常(500001)!"),
    SMSCodeSendError(500002, "短信验证码发送失败!"),
    SMSCodeAlreadySend(500006, "短信验证码已发送, 请勿重复获取!"),
    RequiresCaptcha(500007, "需要图形验证码!"),
    CaptchaCodeError(500008, "图形验证码输入错误!"),
    CaptchaCodeErrorTimeOut(500008, "图形验证码已过期"),
    InvalidResponseError(500003, "无效响应!"),

    // ServiceUnavailableError (503001 - 503099)
    DBMongoSaveError(503001, "Mongo入库失败!"),
    DBMongoReadError(503003, "Mongo读库失败!"),
    DBMysqlSaveError(503002, "Mysql入库失败!"),
    AnnouncementNotFoundError(503007, "未设置首页滚动!"),

    NotModified(304, "Not Modified"),
    BadRequest(400, "Bad Request"),
    Unauthorized(401, "Unauthorized"),
    ForbiddenError(403, "Forbidden"),
    NotFoundError(404, "Not Found"),
    NotSupportError(405, "Not support"),
    TooManyRequestsError(429, "Too Many Requests"),
    InternalServerError(500, "Internal Server Error"),
    ServiceUnavailableError(503, "Service Unavailable"),
    GateWayTimeOutError(504, "Gateway timeout"),
    ParameterError(400001, "请确认参数是否正确!"),
    ParameterSimplePwdError(400001, "密码请使用6至12位的字母或数字组合！"),
    ConnectionResetError(500001, "连接中断!"),
    TimedOutError(500002, "网络请求超时!"),
    SSLConnectionError(500003, "数据源SSL连接错误!"),
    HttpInternalServerError(500004, "数据源Http内部服务器错误!"),
    ConnectionRefusedError(500005, "连接被拒绝!"),
    NoRouteToHostError(500007, "无法连接到主机"),
    HttpAccessForbiddenError(401005, "访问被拒绝!"),
    HttpNotFoundError(404003, "资源未找到!"),
    SignatureNoFoundError(401010, "无签名!"),
    SignatureInvalidError(401011, "签名无效!"),
    AccountAuthFailureError(401013, "用户名或密码不正确!");

    private int code;
    private String msg;

    ExceptionEnum(int errCode, String errMsg) {
        this.code = errCode;
        this.msg = errMsg;
    }

    public static ExceptionEnum codeOf(int code) {
        for (ExceptionEnum ee : values()) {
            if (ee.code == code) {
                return ee;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

}
